Description of the Meshgrid function in Numpy and two application scenarios: numpymeshgrid
Recently, we have seen the use of meshgrid in several places, although we have noticed the use of meshgrid before.However, I am not very impressed with the use cases of meshgrid.Therefore, this article will further introduce the usage of
Http://blog.sina.com.cn/s/blog_67f37e760101bu4e.htmlInstance result http://wenku.baidu.com/link?url= Sigsfzixus1e1vzwtixqxdjg5y9sy4tu1w8txgk147hdollcgpffjx8ywdmih1pykqsi5rp8gkmnmpslhh-iuagjml8hsrhzqsstpmnbjdyAbout Matlab interpolation (interpolation) http://blog.sina.com.cn/s/blog_4c7482f101009vm2.htmlMatlab Two-dimensional interpolation--interp2 and Griddata fromhttp://3y.uu456.com/bp_32jw03xolo8iiwn479ge_1.html1. MeshgridThe Meshgrid is used to gene
Linspace can be used to implement sampling at the same interval.numpy.linspace(start, stop, num=50, endpoint=true, retstep=false , dtype=none) The return value is Numpy.ndarray.Attach an example:Np.linspace (1,10,10) Array ([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])Because endpoint=true by default, the resulting number is in the form of this$x _{k} = x_{min} + \frac{x_{max}-x_{min}}{num-1} * (k-1) $,${k}\in{[1,m]}$It can be understood that this is a straight line, to be di
usage is [x Y]=meshgrid (A, b);
Meshgrid
Where A and B are all one-dimensional arrays
Give some examples
1. A=[1 2 3] b=[2 3 4]
Then the resulting matrix X and y are all 3*3 matrices.
where each row of the x matrix is [1 2 3], the number of rows is determined by the length of the array b
Each column of the Y-matrix is [2 3 4], and the number of columns is determined by the length of the array a
>> [x Y]=
Peaks of Matlab, mesh, and meshgrid Functions
Peaks:
MATLAB provides a peaks function to generate a concave and convex surface. It contains three local vertices and three Local Minimization points. The equation is:
I:
Peaks: 49*49 matrix (n = 49) by default)
II:
Z = peaks (N): The larger the value of N, the smaller the interval between neighboring points. Therefore, the smoother the line. The returned Z is a two-dimensional matrix.
For details, re
I. The role of Meshgrid
First, the function of Meshgrid is to extend the two vectors horizontally and vertically.
>>> import NumPy as NP
>>> x=np.arange ( -1,3)
>>> x
Array ([-1, 0, 1, 2])
>>> Y=np.array ([7,8,9])
>>> y
Array ([7, 8, 9])
>>> Xe,ye=np.meshgrid (x,y)
>>> XE
Array ([[1, 0, 1, 2], [-1, 0, 1, 2],
[-1, 0, 1, 2]]
>>> ye
Array ([[7, 7, 7, 7],
[8, 8, 8, 8],
[9, 9, 9,
)Returns the matrix Zi, which contains the elements corresponding to the parameters XI and Yi (which can be a vector or a matrix of the same type), that is, Zi (I, j) semi [XI (I, j), Yi (I, j)]. You can input row vectors and column vectors XI and Yi. In this case, the output vector Zi is the same as the matrix meshgrid (XI, Yi. It also depends on the two-dimensional functions z = f (x, y) determined by the input matrix X, Y, and Z ). Parameters X and
numerical gradient of F. FX corresponds to the differential in the X direction.
[X, y] = meshgrid (-2:. 2,-2:. 2 );Z = x. * exp (-X. ^ 2-y. ^ 2 );[PX, Py] = gradient (z,. 2,. 2 );Contour (z), hold on draw contourQuiver (PX, Py)
MATLAB string operationUse the sym command to create an expressionF = Sym ('cos (x) + sin (x) ') or Syms X, F = cos (x) + sin (X)Diff (f) for its Derivative(You can also directly use the command F = diff ('cos (x) + cos (y )')
symbol expression contains the letter D to denote the differential operation, d2,d3 corresponding to the second, third derivative, d2y that D2Y/DT2 t defaultY=dsolve (' dy=f (y) ') single equation, single output[U,v]=dsolve (' Du=f (u,v) ', ' Dv=g (u,v) ') 2 equations, 2 outputsS=dsolve (' Dx=f (x, y, z) ', ' dy=g (x, y, z) ', ' dz=k (x, y, z) ')S.x s.y s.z 3 equations, schema array
Dsolve (' dx=-a*x ') Result: C1*exp (-a*t) is not given the initial value, so the result contains parametricX=dso
Four-dimensional mapping:
This problem can be achieved with the slice command:%%%=================================%%%Clear All[x, Y, z] = Meshgrid (0:.5:10,0:.5:10,0:.5:10);c = x.^2+y.^2+z.^2;xs = [0,2,4,6,8,10];YS = [4];ZS = [6]; % Xs,ys,zs can determine the form and position of the slice, Helpslice can understand its specific meaningSlice (X,y,z,c,xs,ys,zs)ColorMap HSV
Of course, as long as Doc Surf, you will find, in fact, the surf command has it
'), (' F ', ' + ', 58.0 ')],dtype=[(' Gender ', ' | S1 '), (' Age ', ' Iii. Generating sequencesArange ([Start,] stop[, step,][, Dtype]) returns the value of the uniform interval within a given interval.Linspace (Start, stop[, num, endpoint, ...]) Returns the number of evenly spaced intervals within the specified interval.Logspace (Start, stop[, NUM, endpoint, base, ...]) Returns the number evenly spaced on the order of magnitude.Geomspace (Start, stop[, num, endpoint, Dtype]) returns the av
, divide Area D into m × n small rectangles by dividing points into straight lines of the parallel axis. Generate a plane grid coordinate matrix that represents the coordinates of each vertex of a small rectangle, and use the relevant function plot.
There are two ways to generate a grid coordinate matrix in a plane area:
Generate with matrix operations.
X = A: DX: B;
Y = (C: Dy: d )';
X = ones (SIZE (y) * X;
Y = y * ones (SIZE (x ));
After the preceding statement is executed, each row of matrix
},2), i);% Applied Color Map IEndEndAxis equalAxis ([-0.2 1.6-0.5 2.5])box onTriangular split[X,y]=meshgrid (1:15,1:15);Tri=delaunay (x, y);Z=peaks (15);Trimesh (Tri,x,y,z)6. TetrahedronD=[-1 1];[X,y,z]=meshgrid (d,d,d);% defines a cubeX=[x (:); 0];Y=[y (:); 0];Z=[z (:); 0];%[x,y,z] Add the center of the cube vertices respectivelyX=[x (:) y (:) z (:)];Tes=delaunayn (X);% returns the array value of MXNTetram
Zookeeper
3D data draw lip image mainly consists of two parts, one is the lip in the X-Y plane raster, one is according to the corresponding Z axis coloring. It mainly uses meshgrid, surf, and shading in MATLAB.1. Use meshgrid to generate a grid
Meshgrid (x, y) uses the vector X and vector y to generate the raster data point matrices X and Y required for drawing
Matlab meshgrid Function
Meshgrid is used to generate grids from arrays a and B. The size of the generated grid matrix A and B is the same. It can also be higher-dimensional.
[A, B] = Meshgrid (a, B)Generate the matrices a and B of size (B) Xsize (. These matrices represent the x and y coordinates of the entire rectangular area.
It is equivalent to adding a from
Data
= load (' hv_re.txt ');
X1 = Data (:, 1);
Y1 = data (:, 2);
Z1 = Data (:, 3);
% diluted to avoid insufficient memory
count = 1; % new variable counter
interval = 10000;% thinning interval for
i = 1:interval:length (x1)
x (count, 1) = X1 (i, 1);
Y (count, 1) = Y1 (i, 1);
Z (count, 1) = Z1 (i, 1);
Count = count + 1;
End
% plot3 figure
;
PLOT3 (x, y, Z, ' * ');
View (0, 90); % point of view, from top to bottom see
figure of Scatter chart
;
Scatter (x, y, +, Z, ' fill
top down, the surf graph, the plot3 line graph, the quiver two-dimensional speed graph with a direction arrow, the surf surface graph, the surfc has a basic isoplot, And the surfl has a brightness curve graph. The waterfall has no cross lines.3Axis correction axis attribute CLF clear graph window clabel place contour label close graph window figure create or select graph window getframe capture animation 2D grid place grid griddata Interpolation of drawing data hidden concealed Grid graph line
vector x, the column vector y, and then the length of the vector to build 1-matrix, multiply the vector by multiplying the resulting 1-matrix, generate mesh matrix, their values correspond to the x-y coordinate plane; Next, calculate the radius of each grid point Finally, the function value matrix Z is computed. The mesh function is used to get the graph. The first statement X is assigned to the definition field, the function is evaluated on it, the third statement establishes a repeating row o
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.